home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / news / suck-2.6 / suck-2 / suck-2.6.3 / chkhistory_db.c < prev    next >
C/C++ Source or Header  |  1996-03-28  |  3KB  |  133 lines

  1. /* If we use history databases, then these routines will */
  2. /* get compiled and used.  If we don't, the routines in chkhistory.c will */
  3. /* be used. */
  4.  
  5. #include <stdio.h>
  6. #include <netdb.h>
  7. #include "config.h"
  8. #include "suck.h"
  9. #include "both.h"
  10. #include "chkhistory.h"
  11.  
  12. #ifdef TIMER
  13. #include "timer.h"
  14. #endif
  15. #ifdef USE_DBM
  16. #    include <dbm.h>
  17. #    define close_history() dbmclose();
  18. #endif
  19.  
  20. #ifdef USE_NDBM
  21. #    include <ndbm.h>
  22. #    include <fcntl.h>
  23.     static DBM *db = NULL;    /* I know this isn't too pretty, but its the easiest way to do it */
  24. #    define close_history() dbm_close(db)
  25. #endif
  26.  
  27. #ifdef USE_DBZ
  28. #    include <dbz.h>
  29. #    define close_history() dbmclose()
  30. #endif
  31.  
  32. /* function prototypes */
  33. int open_history(void);
  34. int  check_history(char *);
  35. /*---------------------------------------------------------------------------------------------------*/
  36. void chkhistory(PMaster master) {
  37.  
  38.     PList curr, prev;
  39.     int nrfound = 0;
  40.  
  41.     if(open_history() != TRUE) {
  42.         fprintf(master->msgs, "Unable to open %s\n", HISTORY_FILE);
  43.     }
  44.     else {
  45.  
  46.         fprintf(master->msgs, "Processing History Database\n");
  47. #ifdef TIMER
  48.         TimerFunc(TIMER_START, 0L);
  49. #endif
  50.  
  51.         /* okay cycle thru our list, checking each against the history DB */
  52.         curr = master->head;
  53.         prev = NULL;
  54.         
  55.         while(curr != NULL ) {
  56.             if(check_history(curr->msgnr) == TRUE) {
  57. #ifdef DEBUG2
  58.                 do_debug("Matched %s, nuking\n", curr->msgnr);
  59. #endif
  60.                 /* matched, nuke it */
  61.                 nrfound++;
  62.                 master->nritems--;
  63.                 if(prev == NULL) {
  64.                     /* remove master node */
  65.                     master->head = curr->next;
  66.                     free_one_node(curr);
  67.                     curr = master->head;    /* next node to check */
  68.                 }
  69.                 else {
  70.                     prev->next = curr->next;
  71.                     free_one_node(curr);
  72.                     curr = prev->next;    /* next node to check */
  73.                 }
  74.             }
  75.             else {
  76.                 /* next node to check */
  77.                 prev = curr;
  78.                 curr = curr->next;
  79.             }
  80.         }
  81. #ifdef TIMER
  82.         fprintf(master->msgs, "%s\n", TimerFunc(TIMER_TIMEONLY, 0l));
  83. #endif
  84.         close_history();
  85.         fprintf(master->msgs, "Processed history, %d dupes removed\n", nrfound);
  86.     }
  87.     return;
  88. }
  89. /*------------------------------------------------------------------------*/
  90. int open_history(void) {
  91.     
  92.     int retval = FALSE;
  93.  
  94. #if defined (USE_DBM) || defined (USE_DBZ)
  95.  
  96.     if(dbminit(HISTORY_FILE) >= 0) {
  97.         retval = TRUE;
  98.     }
  99. #else
  100.  
  101.     if((db = dbm_open(HISTORY_FILE, O_RDONLY, 0)) != NULL) {
  102.         retval = TRUE;
  103.     }
  104. #endif
  105.  
  106.     return retval;
  107. }
  108. /*----------------------------------------------------------------*/
  109. int check_history(char *msgid) {
  110.  
  111.     datum input, result;
  112.  
  113.     input.dptr = msgid;
  114.     input.dsize = strlen(msgid) +1;
  115.  
  116. #if defined (USE_DBM)
  117.     
  118.     result = fetch(input);
  119.  
  120. #elif defined (USE_DBZ) 
  121.  
  122.     result = dbzfetch(input);
  123.  
  124. #elif defined (USE_NDBM)
  125.  
  126.     result = dbm_fetch(db, input);
  127.  
  128. #endif
  129.  
  130.     return (result.dptr != NULL) ? TRUE : FALSE;
  131.  
  132. }        
  133.